# 1、图片链接
# 2、星级
# 3、书名
# 4、价格
import requests
from lxml import etree
url = 'https://books.toscrape.com/'
response = requests.get(url)
print(response.status_code)
# print(response.text)
html = response.text
# xpath的使用
# 1、得到一个etree对象
ehtml = etree.HTML(html)
# 2、通过xpath查找
# 图片链接1
xtitle = ehtml.xpath("//div[@class='image_container']/a//@src")
print(xtitle)
# 星级
xtitle = ehtml.xpath("//article[@class='product_pod']/p[1]/@class[1]")
print(xtitle)
# 书名
xtitle = ehtml.xpath("//article[@class='product_pod']/h3//@title")
print(xtitle)
# 价格1
xtitle = ehtml.xpath("//div[@class='product_price']/p[1]/text()")
print(xtitle)
